//
//  MTSearchFriendListCell.swift
//  MT
//
//  Created by ooops on 2020/5/6.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTSearchFriendListCell: UITableViewCell {
    
    var model: MTSearchUserInfoModel? {
        didSet {
            if let m = model {
                if let href = m.headerUrl {
                    userIconImage.mtSetImage(href, nil)
                }
                
                if let nickName = m.nickname {
                    userNickNameLabel.text = nickName
                }
                
                if let mtNum = m.id {
                    userMTNumberabel.text = "\(mtNum)"
                }
                
                //if let phone = m.ph
            }
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    class func reuseIdentity() -> String {
        return "MTSearchFriendListCellID"
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        makeConstraint()
    }
    
    lazy var userIconImage: UIImageView = {
        let imageV = UIImageView()
        imageV.layer.cornerRadius = 22
        imageV.layer.masksToBounds = true
        return imageV
    }()
    
    lazy var userNickNameLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(14)
        l.textColor = UIColor.text.x1d1a1a
        l.text = "小米dd"
        return l
    }()
    
    lazy var userLevelLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCSemiboldFont(10)
        l.backgroundColor = UIColor(hex: 0xffc000)
        l.textColor = UIColor(hex: 0xFFFFFF)
        l.layer.cornerRadius = 6
        l.layer.masksToBounds = true
        l.text = "M31"
        return l
    }()
    
    lazy var userMTNumberabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCMediumFont(12)
        l.textColor = UIColor.text.x9b9b9b
        l.text = "觅颜号: xxxxxx"
        return l
    }()
    
    lazy var userPhoneNumberabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCMediumFont(12)
        l.textColor = UIColor.text.x9b9b9b
        l.text = "手机号: 1231231234123"
        return l
    }()
    
    private func setupUI() {
        contentView.addSubview(userIconImage)
        contentView.addSubview(userNickNameLabel)
        contentView.addSubview(userLevelLabel)
        contentView.addSubview(userMTNumberabel)
        contentView.addSubview(userPhoneNumberabel)
    }
    
    private func makeConstraint() {
        
        userIconImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.size.equalTo(CGSize(width: 44, height: 44))
        }
        
        userNickNameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(userIconImage.snp.right)
            make.bottom.equalTo(self.snp.centerY).offset(-2)
        }
        
        userLevelLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(userNickNameLabel)
            make.left.equalTo(userNickNameLabel.snp.right).offset(4)
        }
        
        userMTNumberabel.snp.makeConstraints { (make) in
            make.left.equalTo(userNickNameLabel)
            make.top.equalTo(self.snp.centerY).offset(2)
        }
        
        userPhoneNumberabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(userMTNumberabel)
            make.right.equalToSuperview().offset(-10)
        }
        
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
